<?php defined('SYSPATH') or die(); ?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>供应商返佣设置</title>
    {template 'stourtravel/public/public_js'}
    <link type="text/css" href="{$GLOBALS['cfg_plugin_finance_public_url']}css/fx_base.css" rel="stylesheet"/>
    <link type="text/css" href="{$GLOBALS['cfg_plugin_finance_public_url']}css/fx_style.css" rel="stylesheet"/>
    <link type="text/css" href="{$GLOBALS['cfg_plugin_finance_public_url']}css/fx_product.css" rel="stylesheet"/>

    {php echo Common::getScript('config.js');}
    {php echo Common::getScript("uploadify/jquery.uploadify.min.js"); }
    {php echo Common::getCss('uploadify.css','js/uploadify/'); }
    {php echo Common::getCss('base.css,style.css,base_new.css'); }


</head>
<body>
<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td" valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td">
            <!--面包屑-->
            <div>
                <form id="frm">
                    <div class="w-set-con">
                        <div class="cfg-header-bar">
                            <div class="cfg-header-tab">
                                {loop $productlist $product}
                                <span class="item" data-id="{$product['id']}">{$product['modulename']}</span>
                                {/loop}
                            </div>
                            <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
                        </div>
                    </div>
                    <div class="w-set-nr">
                        {loop $productlist $product}
                        <div class="picture ml-10 ratio-content" id="product_{$product['id']}" style="display: none;">
                            <ul class="info-item-block">
                                <li>
                                    <span class="item-hd">公共抽佣类型{Common::get_help_icon('cfg_platform_commission_type')}：</span>
                                    <div class="item-bd">
                                        <label class="radio-label mr-20"><input type="radio" name="cfg_channel_commission_type_{$product['id']}" class="fx_type" value="1" {if $info['cfg_channel_commission_type_'.$product['id']]==1}checked="checked"{/if}>比例</label>
                                        <label class="radio-label mr-20"><input type="radio" name="cfg_channel_commission_type_{$product['id']}" class="fx_type" value="0" {if $info['cfg_channel_commission_type_'.$product['id']]==0}checked="checked"{/if}>现金</label>
                                        <span class="c-999">是按比例计算抽佣金额还是直接抽取固定的金额</span>
                                    </div>
                                </li>
                            </ul>
                            <div class="typecon_1 typecon" style="{if $info['cfg_channel_commission_type_'.$product['id']]!=1}display:none{/if}">
                                <ul class="info-item-block">
                                    <li>
                                        <span class="item-hd">平台抽佣比例：</span>
                                        <div class="item-bd">
                                            <table class="table table-border table-bordered table-striped w300">
                                                <thead>
                                                    <tr>
                                                        <th>渠道</th>
                                                        <th>比例</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                {loop $channel $v}
                                                    <tr>
                                                        <td>{$v['title']}</td>
                                                        <td><input type="text" name="cfg_channel_commission_ratio_{$v['id']}_{$product['id']}" value="{php echo $info['cfg_channel_commission_ratio_'.$v['id'].'_'.$product['id']]}" class="input-text w100" onkeyup="ratio_change($(this))"> %</td>
                                                    </tr>
                                                {/loop}
                                                </tbody>
                                            </table>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                            <div class="typecon_0 typecon" style="{if $info['cfg_channel_commission_type_'.$product['id']]!=0}display:none{/if}">
                                <ul class="info-item-block">
                                    <li>
                                        <span class="item-hd">平台抽佣金额：</span>
                                        <div class="item-bd">
                                            <table class="table table-border table-bordered table-striped w300">
                                                <thead>
                                                <tr>
                                                    <th>渠道</th>
                                                    <th>金额</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                {loop $channel $v}
                                                <tr>
                                                    <td>{$v['title']}</td>
                                                    <td><input type="text" name="cfg_channel_commission_cash_{$v['id']}_{$product['id']}" value="{php echo $info['cfg_channel_commission_cash_'.$v['id'].'_'.$product['id']]}" class="input-text w100" onkeyup="cash_change($(this))"> 元</td>
                                                </tr>
                                                {/loop}
                                                </tbody>
                                            </table>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                            {if St_Functions::open_single_finance_set($product['id'])}
                            <p class="typecon_1 typecon_0 typecon" style="{if $info['cfg_channel_commission_type_'.$product['id']]==2}display:none{/if}">
                                <a data-url="{$prefix_url}/supplier/config_commission_product/typeid/{$product['id']}/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}parentkey/finance/itemid/5" href="javascript:;" class="fl btn btn-primary radius size-S mt-3 config_commission_product">
                                    设置{$product['modulename']}供应商具体抽佣方式
                                </a>
                                <span class="item-text c-999 ml-10">
                                    针对不同供应商设置不同抽佣比例或金额，如果某供应商未设置具体抽佣比例或金额，将使用公共抽佣方式！
                                </span>
                            </p>
                            {/if}
                        </div>
                        {/loop}
                        <div class="clear clearfix pt-20">
                            <a class="btn btn-primary radius size-L ml-115" href="javascript:;" id="btn_save">保存</a>
                        </div>
                    </div>
            </div>
            </form>
            </div>
        </td>
    </tr>
</table>
<script>
    //限制金额最多只能有两位小数
    function cash_change(obj)
    {
        var val = obj.val();
        val = val.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1');
        obj.val(val);
    }
    //限制比例只能是0-100的整数
    function ratio_change(obj)
    {
        var val = obj.val();
        val = val.replace(/[^\d]/g,'').replace(/^0{1,}/g,'');
        if(val>100){
            val = 100;
        }else if(val<0){
            val = 0;
        }
        obj.val(val);
    }
    $(document).ready(function () {
        //配置信息保存
        $("#btn_save").click(function () {
            Ext.Ajax.request({
                url: SITEURL + "{$prefix_url}/supplier/ajax_config_commission_type_save",
                method: "POST",
                isUpload: true,
                form: "frm",
                success: function (response, opts) {
                    var data = $.parseJSON(response.responseText);
                    if (data.status) {
                        ST.Util.showMsg('保存成功!', '4', 2000);
                    }
                }
            });
        })
        //切换
        $(".fx_type").click(function () {
            var typeVal = $(this).val();
            $(this).parents('.ratio-content:first').find(".typecon").hide();
            $(this).parents('.ratio-content:first').find(".typecon_" + typeVal).show();
        });

        $(".item").click(function () {
            $(this).addClass('on');
            $(this).siblings().removeClass('on');
            var id = $(this).attr("data-id");
            $(".ratio-content").hide();
            $("#product_" + id).show();
        });
        $(".item:first").trigger('click');

        //跳转到具体产品设置页面
        $(".config_commission_product").click(function () {
            var $this = $(this);
            var url = SITEURL + $this.attr("data-url");
            ST.Util.addTab($this.text(), url, 0);
        });
    });
</script>
<!--右侧选中效果-->
<script type="text/javascript" src="{$GLOBALS['cfg_plugin_finance_public_url']}js/common.js"></script>

</body>
</html>
